package cn.apelx.store.domain;

import lombok.Getter;
import org.springframework.data.domain.Persistable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 仓库
 *
 * @author apelx
 * @since 2022-04-28
 */
@Getter
@Entity
@Table(name = "store")
public class Store implements Persistable<String>, Serializable {

    @Id
    private String id;

    /**
     * 仓库名
     */
    private String location;

    /**
     * 库存数量
     */
    private BigDecimal stockNum;

    protected Store() {

    }

    public Store(String location, BigDecimal stockNum) {
        this.location = location;
        this.stockNum = stockNum;
    }


    @Override
    public String getId() {
        return this.id;
    }

    @Override
    public boolean isNew() {
        return null == getId();
    }

    public Store subStock(BigDecimal sunNum) {
        this.stockNum = this.stockNum.subtract(sunNum);
        return this;
    }

    public Store addStock(BigDecimal sunNum) {
        this.stockNum = this.stockNum.add(sunNum);
        return this;
    }
}
